<template>
    <div>
        <div style="height: 600px;overflow-y: scroll;">
            <el-form ref="form" :model="form" label-width="80px" class="myform">
                <el-form-item label="流水号">
                    <el-input v-model="form.id" :disabled="true"></el-input>
                </el-form-item>

                <el-form-item label="工会id">
                    <el-input v-model="form.gh_createid"></el-input>
                </el-form-item>

                <el-form-item label="届号">
                    <el-input v-model="form.number"></el-input>
                </el-form-item>

                <el-form-item label="换届开始日期">
                    <el-input v-model="form.changedatestart"></el-input>
                </el-form-item>

                <el-form-item label="任期结束日期">
                    <el-input v-model="form.changedateend"></el-input>
                </el-form-item>

                <el-form-item label="任期（年）">
                    <el-input v-model="form.year"></el-input>
                </el-form-item>

                <el-form-item label="新届号">
                    <el-input v-model="form.newnumber"></el-input>
                </el-form-item>

                <el-form-item label="员工数量">
                    <el-input v-model="form.ygcount"></el-input>
                </el-form-item>

                <el-form-item label="会员代表数">
                    <el-input v-model="form.dbcount"></el-input>
                </el-form-item>

                <el-form-item label="委员数">
                    <el-input v-model="form.wycount"></el-input>
                </el-form-item>

                <el-form-item label="副主席数">
                    <el-input v-model="form.fzxcount"></el-input>
                </el-form-item>

                <el-form-item label="经费审查委员数">
                    <el-input v-model="form.jfsccount"></el-input>
                </el-form-item>

                <el-form-item label="经费审查委员副主席数">
                    <el-input v-model="form.jfsc_fzrcount"></el-input>
                </el-form-item>

                <el-form-item label="女职工委员">
                    <el-input v-model="form.nzgcount"></el-input>
                </el-form-item>

                <el-form-item label="女职工委员副主任">
                    <el-input v-model="form.nzg_fzrcount"></el-input>
                </el-form-item>


            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" @click="Close">取消</el-button>
            <el-button size="mini" type="primary" @click="Save">确认</el-button>
        </div>
    </div>
</template>
<script>

import * as gh_changes from '@/api/gh_changes'
export default {
    name: 'gh_changeedit',
    props: ['id', 'etime'],
    data() {
        return {
            form: {
                //流水号
                id: "",
                //工会id
                gh_createid: "",
                //届号
                number: "",
                //换届开始日期
                changedatestart: "",
                //任期结束日期
                changedateend: "",
                //任期（年）
                year: "",
                //新届号
                newnumber: "",
                //员工数量
                ygcount: "",
                //会员代表数
                dbcount: "",
                //委员数
                wycount: "",
                //副主席数
                fzxcount: "",
                //经费审查委员数
                jfsccount: "",
                //经费审查委员副主席数
                jfsc_fzrcount: "",
                //女职工委员
                nzgcount: "",
                //女职工委员副主任
                nzg_fzrcount: "",
                //
                appstate: "",
                //
                appstatedate: "",
                //
                appstateuserid: "",
                //
                file: "",
                //
                createname: "",
                //
                createdate: "",
                //
                name: "",
                //
                pifu: "",
                //
                titlename: "",
                //
                hongtou_hui: "",
                //
                hongtou_nian: "",
                //
                pffile: "",
                //
                hongtou_wenhao: "",

            }

        }
    },
    watch: {
        'etime': {
            immediate: true, // 将立即以表达式的当前值触发回调
            handler: function () {
                let that = this;
                that.getModel();
            },
            deep: true,

        }
    },
    created() {
        this.init();
    },
    methods: {
        init() {

            //let that = this;
            //加载字典
            //gh_changes.getCategories({ page: 1, limit: 99999, TypeId: "whg_user_type" }).then((response) => {
            //    that.whg_activity_type = [];
            //  that.whg_activity_type = response.data;
            //});
        },
        //获取数据详情
        getModel() {
            let that = this;
            //如果传过来ID则表示编辑状态
            if (that.id != 0) {
                gh_changes.get(this.id).then((response) => {
                    that.form = response.result;
                });
            } else {
                //清空对象内所有值但保留key
                Object.keys(that.form).forEach((key) => (that.form[key] = ''));

                //如需赋默认值请使用此方法
                //that.$set(that.form, "字段", 1);
            }
        },
        //取消编辑
        Close() {
            let that = this;
            that.$emit('dataUpdate', 0);
        },
        //保存数据
        Save() {
            let that = this;

            //编辑状态保存数据
            if (that.id != 0) {
                gh_changes.update(that.form).then((response) => {
                    //提交成功
                    if (response.code == 200) {
                        that.$message({
                            message: response.message,
                            type: 'success'
                        });
                        //通知父页面关闭窗口
                        that.$emit('dataUpdate', that.form.id);
                    } else {
                        that.$message({ message: response.message, type: 'warning' });
                    }
                });
            }
            //添加新数据
            else {
                gh_changes.add(that.form).then((response) => {
                    //提交成功
                    if (response.code == 200) {
                        that.$message({
                            message: response.message,
                            type: 'success'
                        });
                        //通知父页面关闭窗口
                        that.$emit('dataAdd');
                    } else {
                        that.$message({ message: response.message, type: 'warning' });
                    }
                });
            }

        }

    },
}


</script>
<style>
.dialog-footer {
    text-align: right;
    margin-top: 8px;
}

/* 调整文本框 */
.el-form-item__label {

    width: 150px !important;

}

/* 调整输入框 */
.el-form-item__content {

    margin-left: 150px !important;
}
</style>